/************************************************************************/
/*    Author: Scott Bevin                                               */
/************************************************************************/

#pragma once

#include <Ogre.h>
#include "../XDelegates/Delegate.h"
#include "../XFrameworkTypedefsAndDefines.h"

namespace XF
{
	class Body
	{
	private:
		float mOldRadius, mRadius;
		XF::Vector3 mPosition, mOldPosition;
		XF::Vector3 mVelocity;
		int mCollisionCatagory;

		XF::Delegate2<bool, Body*, Body*> mOnCollision;

	public:
		Body(float x, float y, float z, float radius) : 
			mPosition(x, y, z), mRadius(radius),
				mOldPosition(x, y, z), mOldRadius(radius), mCollisionCatagory(-1){}
		Body(): 
			mPosition(0.0f, 0.0f, 0.0f), mRadius(0.0f),
			mOldPosition(0.0f, 0.0f, 0.0f), mOldRadius(0.0f), mCollisionCatagory(-1){}
		Body(XF::Vector3 pos, float radius): 
			mPosition(pos), mRadius(radius),
			mOldPosition(pos), mOldRadius(radius), mCollisionCatagory(-1){}
		Body(Body &body): 
			mPosition(body.mPosition), mRadius(body.mRadius),
			mOldPosition(body.mOldPosition), mOldRadius(body.mOldRadius), mCollisionCatagory(body.mCollisionCatagory){}
		~Body() {}

		void Position(float x, float y, float z)
		{
			mOldPosition = mPosition;
			mPosition = XF::Vector3(x, y, z);
		}

		void Position(XF::Vector3 pos)
		{
			mOldPosition = mPosition;
			mPosition = pos;
		}

		XF::Vector3 Position(){ return mPosition; }
		float X(){return mPosition.x;}
		float Y(){return mPosition.y;}
		float Z(){return mPosition.z;}

		XF::Vector3 Velocity(){ return mVelocity; }
		void Velocity(XF::Vector3 velocity){ mVelocity = velocity; }

		float Radius(){ return mRadius; }
		void Radius(float radius){ mOldRadius = mRadius; mRadius = radius; }

		bool HasMoved(){ return !(mOldPosition != mPosition && mOldRadius == mRadius); }

		void OnCollision(XF::Delegate2<bool, Body*, Body*> function){mOnCollision = function;}
		XF::Delegate2<bool, Body*, Body*> OnCollision(){ return mOnCollision; }

		int CollisionCatagory(){ return mCollisionCatagory; }
		void CollisionCatagory(int catagory){ mCollisionCatagory = catagory; }
	};
}